#ifndef _OCPP_NcUtil_H__
#define _OCPP_NcUtil_H__

#include "ncFile.h"
#include "ncVar.h"
#include "ncDim.h"
#include "OCVolume/VolumeOptions.h"
#include "OCVolume/VolumeExtent.h"
#include "OCMain/Log.h"
#include "NetCDFDef.h"

using namespace netCDF;

namespace OCPP
{
	using namespace Volume;
	using NcVarIndex = std::tuple<size_t, String>;

	class NcUtil
	{
	public:
		static size_t getVarSize(const NcVar& var);

		static FloatVector readFloat(const NcVar& var);

		static IntVector readInt(const NcVar& var);

		static String readStringAttr(const NcAtt& attr);
		static float readFloatAttr(const NcAtt& attr, float defaultValue);

		static bool isDimT(String name, const VolumeOptions& options);
		static bool isDimZ(String name, const VolumeOptions& options);
		static bool isDimY(String name, const VolumeOptions& options);
		static bool isDimX(String name, const VolumeOptions& options);

		template<class T> static void getTypeDataToFloat(FloatVector& data, const NcVar& var)
		{
			size_t size = data.size();
			T data1;
			data1.resize(size);
			var.getVar(&data1[0]);
			for (size_t i = 0; i < size; i++)
			{
				data[i] = (float)data1[i];
			}
		}

		template<class T> static void getTypeDataToInt(IntVector& data, const NcVar& var)
		{
			size_t size = data.size();
			T data1;
			data1.resize(size);
			var.getVar(&data1[0]);
			for (size_t i = 0; i < size; i++)
			{
				data[i] = (int)data1[i];
			}
		}
	};
}


#endif // !_OCPP_NcTime_H__
